home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / zstud1 / czip.cp_ / CZIP.CPP
Encoding:
C/C++ Source or Header  |  1994-04-09  |  5.4 KB  |  156 lines

  1. // czip.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "zdemo.h"
  6. #include "czip.h"
  7. #include <zip.h>
  8. #include "mainfrm.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15.                 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16.                 // CCzip dialog box
  17.                 
  18.                 
  19.                 CCzip::CCzip(CWnd* pParent /*=NULL*/)
  20.                     : CDialog(CCzip::IDD, pParent)
  21.                 {
  22.                     //{{AFX_DATA_INIT(CCzip)
  23.                         // NOTE: the ClassWizard will add member initialization here
  24.                     //}}AFX_DATA_INIT
  25.                 }
  26.                 
  27.                 void CCzip::DoDataExchange(CDataExchange* pDX)
  28.                 {
  29.                     CDialog::DoDataExchange(pDX);
  30.                     //{{AFX_DATA_MAP(CCzip)
  31.                         // NOTE: the ClassWizard will add DDX and DDV calls here
  32.                     //}}AFX_DATA_MAP
  33.                 }
  34.                 
  35.                 BEGIN_MESSAGE_MAP(CCzip, CDialog)
  36.                     //{{AFX_MSG_MAP(CCzip)
  37.                     ON_EN_CHANGE(IDC_EDITFILENAME, OnChangeEditfilename)
  38.                     ON_EN_CHANGE(IDC_EDITFILEPATH, OnChangeEditfilepath)
  39.                     //}}AFX_MSG_MAP
  40.                 END_MESSAGE_MAP()
  41.                 
  42.                 
  43.                 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  44.                 // CCzip message handlers
  45.                 
  46.                 ////////////////////////////////////////////////////////
  47.                 // WM_INITDIALOG
  48.                 BOOL CCzip::OnInitDialog()
  49.                     {
  50.                     CString CurrentPath, Temp;                                   
  51.                     CDialog::OnInitDialog();
  52.                     if ( CurrentZipFile == "" )    // a zip file is compulsory
  53.                         {
  54.                         MessageBox( "Please select a zip file!" );
  55.                         PostMessage( WM_CLOSE );
  56.                         return TRUE;
  57.                         }
  58.                     // we just set the default values
  59.                     CheckDlgButton( IDC_CHECKPATH, 1 );
  60.                     CheckRadioButton( IDC_RADIOALWAYS, IDC_RADIOUPDATE, IDC_RADIOALWAYS );
  61.                     CurrentPath = GetPathFromFileName( CurrentZipFile );
  62.                     Temp = CurrentPath;
  63.                     Temp = Temp.Right(1);
  64.                     if (  Temp != "\\" )
  65.                         CurrentPath += "\\";
  66.                     SetDlgItemText( IDC_EDITFILEPATH, CurrentPath );
  67.                     SetDlgItemText( IDC_EDITFILENAME, "*.*");
  68.                     SendDlgItemMessage( IDC_EDITFILENAME , EM_LIMITTEXT, 178 );
  69.                     SendDlgItemMessage( IDC_EDITFILEPATH , EM_LIMITTEXT, 178 );
  70.                     GetDlgItem( IDC_EDITFILENAME)->SetFocus( );                                                
  71.                     GetDlgItem( IDC_EDITFILENAME)->SendMessage(  EM_SETSEL, TRUE, MAKELONG( 0, -1L ));
  72.                     return FALSE;  // return TRUE  unless you set the focus to a control
  73.                     }
  74.                 
  75.                 
  76.                 ////////////////////////////////////////////////////////
  77.                 // WM_COMMAND ( IDOK )
  78.                 void CCzip::OnOK()
  79.                     {    
  80.                     CString Mask, FileName, Path;       
  81.                     int Overwrite;
  82.                     BOOL Recurse, KeepPath;
  83.                     
  84.                     GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ),178);
  85.                     FileName.ReleaseBuffer();
  86.                     // we simply call the zip main function
  87.                     GetDlgItemText( IDC_EDITFILEPATH, Path.GetBuffer( 180 ),178);
  88.                     Path.ReleaseBuffer();
  89.                     if (( FileName.GetLength() == 0 ) || ( Path.GetLength() == 0 ))
  90.                         {
  91.                         MessageBeep( 0 );
  92.                         GetDlgItem( IDOK )->EnableWindow( FALSE );    
  93.                         return;
  94.                         }
  95.                     if ( (FileName.GetLength() + Path.GetLength() ) > 180 )
  96.                         {
  97.                         MessageBox( "Path plus filter must not be longer than 180 characters!","Zip Studio", MB_OK | MB_ICONEXCLAMATION );
  98.                         GetDlgItem( IDOK )->EnableWindow( FALSE );    
  99.                         return;
  100.                         }
  101.                     if ( Path.Right(1) != "\\" )
  102.                         Path += "\\";
  103.                     Mask = Path + FileName;
  104.                     if ( IsDlgButtonChecked( IDC_RADIOUPDATE) )
  105.                         Overwrite = OVERWRITE_UPDATE;
  106.                     else if ( IsDlgButtonChecked( IDC_RADIOPROMPT) )
  107.                         Overwrite = OVERWRITE_PROMPT;
  108.                     else if ( IsDlgButtonChecked( IDC_RADIONEVER) )
  109.                         Overwrite = OVERWRITE_NEVER;
  110.                     else
  111.                         Overwrite = OVERWRITE_ALWAYS;                                                                                                    
  112.                     
  113.                     Recurse = IsDlgButtonChecked( IDC_CHECKRECURSE)?1:0;
  114.                     KeepPath = IsDlgButtonChecked( IDC_CHECKPATH)?1:0;
  115.                     // we give correct values to mainframe
  116.                     ((CMainFrame*)AfxGetMainWnd())->sMask = Mask;
  117.                     ((CMainFrame*)AfxGetMainWnd())->iOverwrite = Overwrite;
  118.                     ((CMainFrame*)AfxGetMainWnd())->bRecurse = Recurse;
  119.                     ((CMainFrame*)AfxGetMainWnd())->bPath = KeepPath;
  120.                     
  121.                     // Launch the zip process
  122.                     ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_ZIP );
  123.                     CDialog::OnOK();
  124.                     }
  125.                 
  126.                 
  127.                 ////////////////////////////////////////////////////////
  128.                 // WM_COMMAND ( EN_CHANGE , IDC_EDITFILENAME )
  129.                 void CCzip::OnChangeEditfilename()
  130.                     {
  131.                     // Disable the OK button if no filename
  132.                     CString Temp;
  133.                     GetDlgItemText( IDC_EDITFILENAME, Temp.GetBuffer(160), 158 );
  134.                     Temp.ReleaseBuffer();
  135.                     if ( Temp.GetLength() == 0 )
  136.                         GetDlgItem( IDOK )->EnableWindow( FALSE );
  137.                     else
  138.                         GetDlgItem( IDOK )->EnableWindow( TRUE );    
  139.                     }
  140.                 
  141.                 
  142.                 ////////////////////////////////////////////////////////
  143.                 // WM_COMMAND ( EN_CHANGE, IDC_EDITFILEPATH )
  144.                 void CCzip::OnChangeEditfilepath()
  145.                     {
  146.                     // Disable the OK button if no path
  147.                     CString Temp;
  148.                     GetDlgItemText( IDC_EDITFILEPATH, Temp.GetBuffer(160), 158 );
  149.                     Temp.ReleaseBuffer();
  150.                     if ( Temp.GetLength() == 0 )
  151.                         GetDlgItem( IDOK )->EnableWindow( FALSE );
  152.                     else
  153.                         GetDlgItem( IDOK )->EnableWindow( TRUE );    
  154.                         
  155.                     }
  156.